package com.thread.sync.sync07;

import java.util.Random;

//客户端
public class Test {
    public static void main(String[] args) throws Exception {
        //工人数量越多,速度越快
        Master master = new Master(20, Worker01.class);//子类
        //创建任务并提交给master
        for (int i = 1; i <= 100; i++) {
            MyTask task = new MyTask();
            task.setId(i);
            task.setPrice(new Random().nextInt(1000));
            master.submitTask(task);
        }
        //执行任务
        master.executeTask();
        long start = System.currentTimeMillis();//开始时间
        while (true) {
            if (master.isFinished()) {//任务完成,计算结果
                long end = System.currentTimeMillis() - start;
                int priceResult = master.getResult();
                System.out.println("最终结果：" + priceResult + ", 执行时间：" + end);
                break;
            }
        }
    }
}
